<template>
    <div class="room-give-gold-box">
        <div class="give">
            <mt-field label="赠送用户" placeholder="请输入用户名" v-model="userName"></mt-field>
            <mt-field label="金币数量" placeholder="请输入金币数量" type="number" v-model="gold"></mt-field>
        </div>
        <div class="act">
            <mt-button class="btn" size="small" type="primary" @click="submit" :disabled="loading">
                <span v-if="!loading">确定</span>
                <mt-spinner type="triple-bounce" color="white" v-if="loading"></mt-spinner>
            </mt-button>
        </div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui'
    import apiUrl from '@/api/apiUrl'
    export default {
        name: "index",
        data () {
            return {
                userName: '',
                gold: '',
                loading: false
            }
        },
        methods: {
            submit () {
                // console.log('123')
                this.$set(this, 'loading', true)
                if (!this.userName) {
                    return Toast('用户名不能为空')
                }
                if (!this.gold) {
                    return Toast('金币不能为空')
                }
                let params = new URLSearchParams();
                params.append('user_name', this.userName)
                params.append('number', this.gold)
                params.append('room_id', this.$route.query.room_id)

                this.$http.post(apiUrl.room.giveGold, params).then(res => {
                    if (res.data.code === 0) {
                        Toast('赠送成功')
                    } else {
                        Toast(res.data.msg)
                    }
                this.$set(this, 'loading', false)
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped lang="less">
    @import "../../../assets/css/bases";
    .act {
        margin-top: @lager;
        display: flex;
        justify-content: center;
        align-items: center;
        .btn {
            width: 80%;
        }
    }
</style>